﻿using System;
using System.IO;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;

namespace Htm2Pdf.Convertor
{
    public static class UrlChecker
    {
        public static void CheckUrl(string url)
        {
            try
            {
                WebRequest req = WebRequest.Create(url);
                req.Method = "HEAD";
                HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

                if (resp.StatusCode != HttpStatusCode.OK)
                    throw new PdfConvException(string.Format("Url '{0}' doesn't exist", url));

                if (resp.Headers["Content-Type"].StartsWith("text/html") == false)
                    throw new PdfConvException(string.Format("Url '{0}' is not a html document"));
               
            }
            catch (WebException webException)
            {
                throw  new PdfConvException(webException.Message);
            }
        }

      
    }
}
